﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class paymoney : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!func.isordinfor(Session["usr"].ToString()))
        {
            Response.Write("<script>alert('您还没有订房信息，请订房后重试');location.href='" + Request.UrlReferrer.ToString() + "';</script>");
        }
        else
        {
            int pay = 0;
            int dates = 0;
            Session["allpay"] = null;
            DataSet ds = func.oderinfor(Session["usr"].ToString());
            txtdates.Text = ds.Tables[0].Rows[0][3].ToString();
            Session["allpay"] = ds.Tables[0].Rows[0][6].ToString();
            dates = int.Parse(ds.Tables[0].Rows[0][5].ToString());
            txtpay.Text = Session["allpay"].ToString();
            

        }
    }

    protected void btn_Click(object sender, EventArgs e)
    {
        DataSet ds = func.ds(Session["usr"].ToString());
        int sum = 0;
        sum = int.Parse(ds.Tables[0].Rows[0][5].ToString());
        if(sum<int.Parse(Session["allpay"].ToString()))
        {
            Response.Write("<script>alert('余额不足，请充值后再试');location.href='" + Request.UrlReferrer.ToString() + "';</script>");

        }
        else
        {
            ds.Clear();
            ds = func.oderinfor(Session["usr"].ToString());

            int rno = int.Parse(ds.Tables[0].Rows[0][7].ToString());

            if (func.jsdel(Session["usr"].ToString()))
            {
                int asum = 0;
                asum = sum - int.Parse(Session["allpay"].ToString());
                if (func.czje(Session["usr"].ToString(),asum))
                {
                    if(func.updstatus(rno,1))
                    {
                        Response.Write("<script>alert('结算成功，正在前往功能页面');location.href='user_func.aspx';</script>");

                    }
                    else
                    {
                        Response.Write("<script>alert('操作异常，稍后再试')</script>");

                    }

                }
                else
                {
                    Response.Write("<script>alert('操作异常，稍后再试')</script>");

                }
            }
            else
            {
                Response.Write("<script>alert('操作异常，稍后再试')</script>");

            }
        }
       
       
    }
}